﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace Book
{
    public partial class Form5_2 : Form
    {
        public Form5_2()
        {
            InitializeComponent();
        }

        private void 查看读者信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form5_1 form5_1 = new Form5_1();
            form5_1.Show();
        }

        private void 添加图书ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form5_2 form5_2 = new Form5_2();
            form5_2.Show();
        }

        private void 添加图书_Click(object sender, EventArgs e)
        {
               DialogResult result = MessageBox.Show("确定添加此书籍吗？", "提示", MessageBoxButtons.OKCancel);
               if (result == DialogResult.OK)
               {
                   OleDbConnection DBconnect = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\zAllstation\access\bookmanage.accdb");
                   DBconnect.Open();
                   string sqlcmd = string.Format("insert into [book](书号,书名,类别代码,作者,出版社,出版日期,价格,是否借阅) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}') ", textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text);
                   DataTable dtable = new DataTable();
                   OleDbDataAdapter adt = new OleDbDataAdapter(sqlcmd, DBconnect);
                   adt.Fill(dtable);
                   MessageBox.Show("添加成功");
               }
               if (result == DialogResult.Cancel)
               {
               }
        }

        private void 查看图书ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form5_3 form5_3 = new Form5_3();
            form5_3.Show();
        }

        private void Form5_2_Load(object sender, EventArgs e)
        {
            label9.Text = string.Format("管理员：{0}", UserHelper.UserName);
            timer1.Start();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            form1.Show();
            this.Close();
        }

        private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4_4 form4_4 = new Form4_4();
            form4_4.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.label10.Text = DateTime.Now.ToString(); 
        }
    }
}
